Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

allow $0 expansion in message boxes #347

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
9 changes: 9 additions & 0 deletions src/g_canvas.c
Expand Up @@ -258,6 +258,15 @@ t_canvasenvironment *canvas_getenv(const t_canvas *x)
return (x->gl_env);
}

int glist_getdollarzero(t_glist *gl)
{
t_canvasenvironment *env = canvas_getenv(gl);
if (env)
return env->ce_dollarzero;
else
return 0;
}

int canvas_getdollarzero(void)
{
t_canvas *x = canvas_getcurrent();
Expand Down
13 changes: 9 additions & 4 deletions src/g_text.c
Expand Up @@ -367,6 +367,7 @@ typedef struct _message
t_messresponder m_messresponder;
t_glist *m_glist;
t_clock *m_clock;
int m_dollarzero;
} t_message;

static t_class *messresponder_class;
Expand Down Expand Up @@ -398,28 +399,31 @@ static void messresponder_anything(t_messresponder *x,
outlet_anything(x->mr_outlet, s, argc, argv);
}

void binbuf_doeval(t_binbuf *x, t_pd *target, int argc, t_atom *argv, int dollarzero);
int glist_getdollarzero(t_glist *gl);

static void message_bang(t_message *x)
{
binbuf_eval(x->m_text.te_binbuf, &x->m_messresponder.mr_pd, 0, 0);
binbuf_doeval(x->m_text.te_binbuf, &x->m_messresponder.mr_pd, 0, 0, x->m_dollarzero);
}

static void message_float(t_message *x, t_float f)
{
t_atom at;
SETFLOAT(&at, f);
binbuf_eval(x->m_text.te_binbuf, &x->m_messresponder.mr_pd, 1, &at);
binbuf_doeval(x->m_text.te_binbuf, &x->m_messresponder.mr_pd, 1, &at, x->m_dollarzero);
}

static void message_symbol(t_message *x, t_symbol *s)
{
t_atom at;
SETSYMBOL(&at, s);
binbuf_eval(x->m_text.te_binbuf, &x->m_messresponder.mr_pd, 1, &at);
binbuf_doeval(x->m_text.te_binbuf, &x->m_messresponder.mr_pd, 1, &at, x->m_dollarzero);
}

static void message_list(t_message *x, t_symbol *s, int argc, t_atom *argv)
{
binbuf_eval(x->m_text.te_binbuf, &x->m_messresponder.mr_pd, argc, argv);
binbuf_doeval(x->m_text.te_binbuf, &x->m_messresponder.mr_pd, argc, argv, x->m_dollarzero);
}

static void message_set(t_message *x, t_symbol *s, int argc, t_atom *argv)
Expand Down Expand Up @@ -528,6 +532,7 @@ void canvas_msg(t_glist *gl, t_symbol *s, int argc, t_atom *argv)
x->m_text.te_binbuf = binbuf_new();
x->m_glist = gl;
x->m_clock = clock_new(x, (t_method)message_tick);
x->m_dollarzero = glist_getdollarzero(gl);
if (argc > 1)
{
x->m_text.te_xpix = atom_getfloatarg(0, argc, argv);
Expand Down
32 changes: 21 additions & 11 deletions src/m_binbuf.c
Expand Up @@ -525,18 +525,16 @@ static int binbuf_expanddollsym(const char *s, char *buf, t_atom *dollar0,
context of a message to create a new object; in this case out-of-range '$'
args become 0 - otherwise zero is returned and the caller has to check the
result. */
/* LATER remove the dependence on the current canvas for $0; should be another
argument. */
t_symbol *binbuf_realizedollsym(t_symbol *s, int ac, const t_atom *av,
int tonew)
t_symbol *binbuf_dorealizedollsym(t_symbol *s, int ac, const t_atom *av,
int tonew, int dollarzero)
{
char buf[MAXPDSTRING];
char buf2[MAXPDSTRING];
const char*str=s->s_name;
char*substr;
int next=0;
t_atom dollarnull;
SETFLOAT(&dollarnull, canvas_getdollarzero());
SETFLOAT(&dollarnull, dollarzero);
buf2[0] = buf2[MAXPDSTRING-1] = 0;

substr=strchr(str, '$');
Expand Down Expand Up @@ -582,10 +580,16 @@ t_symbol *binbuf_realizedollsym(t_symbol *s, int ac, const t_atom *av,
return (gensym(buf2));
}

/* for compatibility */
t_symbol *binbuf_realizedollsym(t_symbol *s, int ac, const t_atom *av, int tonew)
{
return binbuf_dorealizedollsym(s, ac, av, tonew, canvas_getdollarzero());
}

#define SMALLMSG 5
#define HUGEMSG 1000

void binbuf_eval(const t_binbuf *x, t_pd *target, int argc, const t_atom *argv)
void binbuf_doeval(t_binbuf *x, t_pd *target, int argc, const t_atom *argv, int dollarzero)
{
t_atom smallstack[SMALLMSG], *mstack, *msp;
const t_atom *at = x->b_vec;
Expand Down Expand Up @@ -662,8 +666,8 @@ void binbuf_eval(const t_binbuf *x, t_pd *target, int argc, const t_atom *argv)
}
else if (at->a_type == A_DOLLSYM)
{
if (!(s = binbuf_realizedollsym(at->a_w.w_symbol,
argc, argv, 0)))
if (!(s = binbuf_dorealizedollsym(at->a_w.w_symbol,
argc, argv, 0, dollarzero)))
{
pd_error(initial_target, "$%s: not enough arguments supplied",
at->a_w.w_symbol->s_name);
Expand Down Expand Up @@ -723,7 +727,7 @@ void binbuf_eval(const t_binbuf *x, t_pd *target, int argc, const t_atom *argv)
if (at->a_w.w_index > 0 && at->a_w.w_index <= argc)
*msp = argv[at->a_w.w_index-1];
else if (at->a_w.w_index == 0)
SETFLOAT(msp, canvas_getdollarzero());
SETFLOAT(msp, dollarzero);
else
{
if (target == &pd_objectmaker)
Expand All @@ -737,8 +741,8 @@ void binbuf_eval(const t_binbuf *x, t_pd *target, int argc, const t_atom *argv)
}
break;
case A_DOLLSYM:
s9 = binbuf_realizedollsym(at->a_w.w_symbol, argc, argv,
target == &pd_objectmaker);
s9 = binbuf_dorealizedollsym(at->a_w.w_symbol, argc, argv,
target == &pd_objectmaker, dollarzero);
if (!s9)
{
pd_error(target, "%s: argument number out of range", at->a_w.w_symbol->s_name);
Expand Down Expand Up @@ -787,6 +791,12 @@ void binbuf_eval(const t_binbuf *x, t_pd *target, int argc, const t_atom *argv)
FREEA(t_atom, mstack, maxnargs, HUGEMSG);
}

/* for compatibility */
void binbuf_eval(const t_binbuf *x, t_pd *target, int argc, const t_atom *argv)
{
binbuf_doeval(x, target, argc, argv, canvas_getdollarzero());
}

int binbuf_read(t_binbuf *b, const char *filename, const char *dirname, int crflag)
{
long length;
Expand Down